package com.dxg.msns.music.mapper;

import com.dxg.msns.music.pojo.Music;
import com.dxg.msns.music.pojo.TypeStatistics;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

@org.apache.ibatis.annotations.Mapper
public interface MusicMapper extends Mapper<Music> {
    @Select("select type_name,count(*) as music_count from music as m left join music_type as mt on m.music_type_id = mt.id GROUP BY type_name")
    @Results(id = "typeStatisticsMap",value = {
            @Result(column = "type_name",property = "typeName"),
            @Result(column = "music_count",property = "musicCount")
    })
    List<TypeStatistics> queryTypeStatistics();

    @Select("SELECT * FROM music WHERE music_author = #{singerName}")
    List<Music> queryMusicBySinger(String singerName);
    @Select("SELECT * FROM music WHERE music_name LIKE CONCAT('%', #{musicName}, '%')")
    List<Music> queryMusicByMusicName(String musicName);


    @Update("UPDATE music SET status = '0' WHERE music_id = #{musicId}")
    int updateStatusByMusicId(@Param("musicId") String musicId);


    @Update("UPDATE music SET music_average_grade = #{musicAverageGrade} WHERE music_id = #{musicId}")
    int updateAverageGradeByMusicId(@Param("musicId") String musicId, @Param("musicAverageGrade") String musicAverageGrade);

}
